<template>
  <nav-bar :showBack="false" text-center title="我的" />
  <view v-if="Object.keys(info).length" class="user_info pr mt-20 flex_a_c"  @click="onLinkSpace(`/pages/ipElite/infomation?id=${dataInfo.info.userData.vipUserId}`)">
    <view class="pr mr-36">
      <image mode="aspectFill"
        class="profile_photo"
        :src="info.headOssUrl || 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/avatar_default.png'"></image>
    </view>
    <view>
      <template v-if="isLogin">
        <view @click="onLinkSpace(`/pages/ipElite/infomation?id=${dataInfo.info.userData.vipUserId}`)" class="nick_name pt-11 ell-1">{{ info.userName }}</view>
        <!-- <view class="roles flex_a_c">
          当前身份：{{ !userFlag ? '卖家' : '买家' }}
          <view class="change flex_center" @click="onChangeUserFlag">
            <image class="change_roles_icon"
              src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/change_roles_icon.png"></image>切换身份
          </view>
        </view> -->
        <view v-if="info.occupation" class="roles_txt">{{ info.occupation.replace(/\,/g, '  ') }}</view>
        <view class="city"><template v-if="info.provinceName">{{ info.provinceName }}</template><template v-if="info.cityName"> · {{ info.cityName }}</template> </view>
        <!-- <view class="flex_a_c">
          <image class="vip_icon" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/vip_icon.png" />{{ info.vipFlag
            ? 'VIP会员' : '未开通' }}
        </view> -->
        <view v-if="!info.entId" @click.stop="onCreateEnt" class="ent_btn">创建企业</view>
        <view class="collect">
          <image class="collect_icon" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/love_icon.png"></image>
          {{ info.collectNum }}
        </view>
      </template>
      <view v-else @click="onLink('/pages/login/index')" class="nick_name ell-1">登录/注册</view>
    </view>
  </view>
  <image class="invite" @click="onLink('/pages/invite/index')" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/center_invite.png"></image>
  <view class="cont flex_r flex_wrap">
    <view :class="['cont_item flex_c flex_a_c', !item.link && 'mask']" v-for="(item, idx) in contList" :key="idx" @click="onLink(item.link)">
      <image class="cont_icon" :src="item.icon"></image>
      <view class="cont_txt">{{ item.title }}</view>
    </view>
    <view v-if="isLogin" class="cont_item flex_c flex_a_c" @click="onLoginOut">
      <image class="cont_icon" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/exit.png"></image>
      <view class="cont_txt">登出账号</view>
    </view>
  </view>
</template>
<script setup>
import { getCenterIndex } from "@/api/center"
import { ref, reactive, onBeforeMount, toRefs } from "vue"
import { onShow, onLoad } from '@dcloudio/uni-app'
import storage from '@/utils/storage'
import { useStore } from "vuex";
let store = useStore()
// entFlag: 0,//是否企业:0：个人；1：企业    个人职业类型
let userFlag = ref(storage.getStorage('userFlag') || 0) //0我有(卖方)  1我要(买方)
let dataInfo = reactive({
  info: {
    userData: {},
    entId: ''
  },
 
})
let contList = ref('')
let onCreateEnt = () => {
  uni.navigateTo({
    url: '/pages/center/infomation/createCompany'
  })
}
let isLogin = ref(storage.getStorage('regiterFlag') === 0 ? true : false)
onShow(async () => {
  isLogin.value = storage.getStorage('regiterFlag') === 0 ? true : false
  if (isLogin.value) {
    await fnGet()
  }
  contList.value = [
    {
      title: '我的招募',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/zhaomu.png',
      link: '/pages/center/ipElite/recruitManage',
      hidden: false
    },
    {
      title: '我的投递',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/toudizhaomu.png',
      link: '/pages/center/ipElite/deliveryManage',
      hidden: false
    },
    {
      title: '代表作品',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/daibiaozuopin.png',
      link: '/pages/center/ipElite/repworksManage',
      hidden: false
    },
    {
      title: '联系记录',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/lianxijilu.png',
      link: '/pages/center/contactList/index',
      hidden: false
    },
    {
      title: '我的收藏',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/wodeshoucang.png',
      link: "/pages/center/collect/index",
      hidden: false
    },
    {
      title: '我的关注',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/wodeguanzhu.png',
      link: "/pages/center/follow/index",
      hidden: false
    },
    {
      title: '实名认证',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/shimingrenzheng.png',
      link: '/pages/center/auth/index',
      hidden: false
    },
    {
      title: '企业信息',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/qiyexinxi.png',
      link: '/pages/ipElite/companyInfomation',
      hidden: !dataInfo.info.entId ? true : false
    },
    {
      title: '账户信息',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/zhanghuxinxi.png',
      link: '/pages/center/infomation/person',
      hidden: false
    },
    {
      title: '邀请记录',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/yaoqingjilu.png',
      link: '/pages/center/invite/index',
      hidden: false
    },
    {
      title: '平台客服',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/pingtaikefu.png',
      link: '/pages/center/contact/index',
      hidden: false
    },
    {
      title: '关于我们',
      icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/gaunyuwomen.png',
      link: '/pages/center/about/index',
      hidden: false
    },
    
    //  {
    //   title: '发票管理',
    //   icon: 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/fapiaoguanli.png'
    // },

  ]
})
onLoad(() => {
  console.log('onLoad')
  // if (storage.getStorage('userFlag') === undefined) {
  //   storage.setStorage('userFlag', 0)
  // }
  // if (isLogin.value) {
  //   fnGetCount(userFlag.value)
  //   fnGet()
  // }
})
let onChangeUserFlag = () => {
  userFlag.value = !userFlag.value ? 1 : 0
  storage.setStorage('userFlag', userFlag.value)
  fnGetCount(userFlag.value)
}
let fnGet = async () => {
  const { code, data } = await getCenterIndex()
  if (code === 200) {
    dataInfo.info = data
  }
}
let onLinkSpace = url => {
   if (!isLogin.value) {
    store.commit('setLoginStatus', true)
    // uni.navigateTo({
    //   url: '/pages/login/index'
    // })
    return false
  }
  let authFlag = storage.getStorage('info').messageFlag
  if (!authFlag) {
    url = '/pages/center/infomation/person'
  }

  uni.navigateTo({
    url: url
  })
}
let onLoginOut = () => {
  storage.removeStorage('info')
  storage.removeStorage('access_token')
  storage.removeStorage('regiterFlag')
  isLogin.value = false
  dataInfo.info = { userData: {}}
  dataInfo.countObj = { rightList: {}}
}
let onLink = url => {
  if (!url) return 
  if (!isLogin.value) {
    store.commit('setLoginStatus', true)
    // uni.navigateTo({
    //   url: '/pages/login/index'
    // })
    return false
  }
  uni.navigateTo({
    url
  })
}
let { info } = toRefs(dataInfo)

</script>
<style lang="scss" scoped>
 .user_info {
    font-size: 24rpx;
    font-weight: 500;
    color: #333333;
    line-height: 42rpx;
    padding-left: 20px;
    width: 710rpx;
    height: 228rpx;
    background: #FFFFFF;
    margin: 0 auto;
    border-radius: 10rpx;
     
    .collect {
      position: absolute;
      font-weight: 500;
      right: 29rpx;
      bottom: 35rpx;
      font-size: 22rpx;
      color: #999999;
      .collect_icon {
        width: 20rpx;
        height: 18rpx;
        margin-right: 8rpx;
      }
    }
    .ent_btn {
      width: 160rpx;
      height: 58rpx;
      background: #E9D1AB;
      border-radius: 29rpx;
      text-align: center;
      line-height: 58rpx;
      font-weight: 500;
      font-size: 26rpx;
      color: #51370F;
      position: absolute;
      top: 52rpx;
      right: 20rpx;
    }

    .profile_photo {
      width: 152rpx;
      height: 152rpx;
      border-radius: 152rpx;
      border: 2rpx solid #fff;
    }
    .auth_icon {
      position: absolute;
      width: 30rpx;
      height: 30rpx;
      right: -3rpx;
      top: 122rpx;
    }

    // .gender {
    //   position: absolute;
    //   width: 37rpx;
    //   height: 37rpx;
    //   top: 19rpx;
    //   right: -12rpx;
    // }

    .nick_name {
      font-size: 36rpx;
      // font-weight: bold;
      line-height: 52rpx;
      font-family: pf_bold;
    }

    .roles {
      line-height: 52rpx;
      font-size: 24rpx;
      font-weight: 500;
      color: #fff;

      .change {
        width: 126rpx;
        height: 34rpx;
        border: 1px solid #EDD4AE;
        border-radius: 17rpx;
        font-size: 22rpx;
        font-weight: 500;
        color: #EFD7B3;
        margin-left: 23rpx;
        text-align: center;

        .change_roles_icon {
          width: 19rpx;
          height: 17rpx;
          margin-right: 5rpx;
        }
      }
    }

    .roles_txt {
      font-size: 24rpx;
      font-family: pf_regular;
      font-weight: 500;
      line-height: 45rpx;
    }
    .city {
      font-weight: 400;
      font-size: 24rpx;
      color: #999999;
      font-family: pf_regulat;
    }

    .vip_icon {
      width: 20rpx;
      height: 20rpx;
      margin-right: 12rpx;
    }
  }
  .invite {
    width: 710rpx;
    height: 140rpx;
    display: block;
    margin: 15rpx auto 0;
  }
  .cont {
    width: 710rpx;
    background: #FFFFFF;
    border-radius: 10rpx;
    margin: 18rpx auto 0;
    padding-top: 44rpx;
    .cont_item {
      width: 25%;
      margin-bottom: 45rpx;
      font-family: pf_regular;
      font-weight: 400;
      font-size: 26rpx;
      line-height: 75rpx;
      color: #333333;
      &.mask {
        opacity: .2;
      }
      .cont_icon {
        width: 40rpx;
        height: 40rpx;
      }
    }
  }
</style>
